package com.lzb.browser.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.ToastUtils;
import com.lzb.browser.BaseAc;
import com.lzb.browser.R;
import com.lzb.browser.databinding.ActivityPatternPasswordBinding;
import com.lzb.browser.view.PatternLockView;

public class PatternPasswordActivity extends BaseAc<ActivityPatternPasswordBinding> implements View.OnClickListener {

    private String password;

    @Override
    protected int onCreate() {
        return R.layout.activity_pattern_password;
    }

    @Override
    protected void initView() {
        mDataBinding.ivPatternPasswordBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        mDataBinding.tvRedraw.setOnClickListener(this);
        mDataBinding.tvConfirm.setOnClickListener(this);

        mDataBinding.patternLockView.setPatternLockViewListener(new PatternLockView.PatternLockViewListener() {
            @Override
            public void onLockEnd(int[] values) {
                if (values.length < 4) {
                    ToastUtils.showShort(getString(R.string.please_sel_more_point));
                    mDataBinding.patternLockView.clearPattern();
                    return;
                }
                password = "";
                for (int value : values) {
                    password += value + "";
                }
            }
        });
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tvRedraw) {//重绘
            mDataBinding.patternLockView.clearPattern();
        } else if (id == R.id.tvConfirm) {//确定
            if (TextUtils.isEmpty(password)) {
                ToastUtils.showShort(getString(R.string.please_draw_password));
                return;
            }
            SetBackupPswActivity.password = password;
            startActivity(SetBackupPswActivity.class);
        }
    }

    @Override
    protected void initData() {

    }
}